package com.itcast.demoone

import android.os.Bundle
import android.widget.SimpleAdapter
import android.widget.Spinner
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class CityIconActivity : AppCompatActivity() {

    // 定义城市数据类，包含图标资源ID、城市名称和城市简介
    data class CityData(val icon: Int, val text: String, var intro: String)

    // 创建城市数据列表，包含多个城市信息
    private val cityList = listOf<CityData>(
        CityData(R.drawable.bj, "北京", "中国首都，历史悠久，政治文化中心，古韵今风交融。"),
        CityData(R.drawable.sh, "上海", "中国东部国际大都市，金融中心，多元文化汇聚。"),
        CityData(R.drawable.gz, "广州", "中国南部沿海城市，经济发达，文化多元。"),
        CityData(R.drawable.sz, "深圳", "中国南部科技创新中心，现代化城市。"),
        CityData(R.drawable.hz, "杭州", "中国东南部历史文化名城，风景秀丽。"),
        CityData(R.drawable.nj, "南京", "中国东部历史文化名城，教育科研中心。"),
    )

    private lateinit var spCity: Spinner

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_city_icon)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        spCity = findViewById(R.id.spinner_icon)
        spCity.adapter = SimpleAdapter(
            this,
            cityList.map {
                mapOf("icon" to it.icon, "text" to it.text, "intro" to it.intro)
            },
            R.layout.item_icon,
            arrayOf("icon", "text", "intro"),
            intArrayOf(R.id.cityIcon, R.id.cityText, R.id.cityIntro)
        )

    }
}